<?php
/**
 * Created by DRCOM.
 * User: GZX
 * Datetime: 2021-11-16 9:17
 */

namespace app\admin\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class Test extends Command
{
    protected function configure()
    {
        $this->setName('test')->setDescription('Here is the remark ');
    }

    protected function execute(Input $input, Output $output)
    {
//        $output->writeln("TestCommand:items");
//        $items = db('itemDetail')->whereNull('myq')->select();
//        foreach ($items as $item){
//            $itemInfo = get_item_info($item['itemid']);
//            $myq = round($itemInfo['max_commission_rate'] * ($itemInfo['zk_final_price'] - $itemInfo['youhuiquan']) / 100, 2);
//            db('itemDetail')->where('itemid',$item['itemid'])->setField('myq',$myq);
//            $output->writeln($item['itemid']);
//            $output->writeln($item['tkmoney']);
//            $output->writeln($myq);
//            $output->writeln(str_repeat('-',21));
//
//            sleep(5);
//        }
//        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxa1d89617c92c2c96&secret=9f6f624ac3ca1e883a24f46a8aeaec64";
//        $contents = file_get_contents($url);
//        echo $contents;
//        $server = 'udp://0.0.0.0:801';
//        $msg_eof = "\n";
//        echo "wechat listening...\n";
////        cache('miniToken', null);
//        $socket = stream_socket_server($server, $errno, $errstr, STREAM_SERVER_BIND);
//        if (!$socket) {
//            die("$errstr ($errno)");
//        }
//        do {
//            $inMsg = stream_socket_recvfrom($socket, 1024, 0, $peer);
//            echo "Client : $peer\n";
//            echo "Receive : $inMsg\n";
//
//            $recv = json_decode($inMsg, true);
//            //给客户端发送信息
//            $token = cache('miniToken');
//
//            $access_token = $token['access_token'];
//            $key = $token['key'];
//            $suffix = $token['SUFFIX'];
//            $crckey = $token['CRC_KEY'];
//
//            // 组装获取手机号的请求地址 jsonpReturn({"result":1,"msg":"Portal协议认证成功！"});
//            $url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" . $access_token;
//            $body = json_encode(['code' => $recv['code']]);
//            echo "body:" . $body . "\n";
//            $info = http_request($url, $body, 'POST');
//            echo "getuserphonenumber:" . $info . "\n";
//            $info_decode = json_decode($info, true);
//            $data = $output = [];
//            if (isset($info_decode['phone_info']['phoneNumber'])) {
//                $pn = $info_decode['phone_info']['phoneNumber'];
//
//            } else {
//                $output = [
//                    'result' => 0,
//                    'msg' => '无法获取手机号码',
//                ];
//            }
//            if (isset($token['ext'])) $output = array_merge($output, json_decode($token['ext'], true));
//            stream_socket_sendto($socket, json_encode($output, true), 0, $peer);
//
//
//        } while (true);

        $list = db('kbsusers')->whereNull('pwd')->select();
        foreach ($list as $v) {
            $hash = trim($v['password']);
//          123
            $pwd = '123';
            $vy = $this->verify($pwd, $hash);
//          123
            $pwd = '1234';
            $vy = $this->verify($pwd, $hash);
//          12345
            $pwd = '12345';
            $vy = $this->verify($pwd, $hash);
//          123456
//            $pwd = '123456';
//            $vy = $this->verify($pwd, $hash);
//          1234567
            $pwd = '1234567';
            $vy = $this->verify($pwd, $hash);
//          12345678
            $pwd = '12345678';
            $vy = $this->verify($pwd, $hash);
//          123456789
            $pwd = '123456789';
            $vy = $this->verify($pwd, $hash);
//          1234567890
            $pwd = '1234567890';
            $vy = $this->verify($pwd, $hash);
//            尝试用账号
            $pwd = $v['account'];
            $vy = $this->verify($pwd, $hash);
//            尝试用a账号
            $pwd = 'a' . $v['account'];
            $vy = $this->verify($pwd, $hash);
//           尝试用aa账号
            $pwd = 'aa' . $v['account'];
            $vy = $this->verify($pwd, $hash);
//           尝试用aaa账号
            $pwd = 'aaa' . $v['account'];
            $vy = $this->verify($pwd, $hash);
//            尝试用mobile
            $pwd = $v['mobile'];
            $vy = $this->verify($pwd, $hash);
//            尝试用amobile
            $pwd = 'a' . $v['mobile'];
            $vy = $this->verify($pwd, $hash);
//            尝试用aamobile
            $pwd = 'aa' . $v['mobile'];
            $vy = $this->verify($pwd, $hash);
//            尝试用aaamobile
            $pwd = 'aaa' . $v['mobile'];
            $vy = $this->verify($pwd, $hash);
//            尝试用ali_account
            $pwd = $v['ali_account'];
            $vy = $this->verify($pwd, $hash);

        }

    }

    function verify($pwd, $hash)
    {
        $vy = password_verify($pwd, $hash);
        if ($vy) {
            db('kbsusers')->where('password', $hash)->update(['pwd' => $pwd]);
            echo $hash . "\t" . $pwd . PHP_EOL;
        }
    }


}